package cn.ynu.cmrs.activity;

import cn.ynu.cmrs.R;
import cn.ynu.cmrs.MyApplication;
import cn.ynu.cmrs.widget.RemoteImageView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

/**
 * Activity representing user's information
 * 
 * @author starsfury
 * 
 */
public class UserInfoActivity extends Activity {

	private ViewHolder vh = new ViewHolder();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		MyApplication.allActivity.add(this);
		setContentView(R.layout.userinfo);
		prepareView();
	}

	private void prepareView() {
		vh.ivItemUserIcon = (RemoteImageView) findViewById(R.id.ivItemPortrait);
		vh.tvItemUserInfo = (TextView) findViewById(R.id.tvItemCollegeName);
		vh.tvItemID = (TextView) findViewById(R.id.tvItemID);
		vh.tvItemPhone = (TextView) findViewById(R.id.tvItemPhoneNumber);
		vh.tvItemQQ = (TextView) findViewById(R.id.tvItemQQ);
		vh.tvItemEmail = (TextView) findViewById(R.id.tvItemEmail);
		vh.tvItemNickName = (TextView) findViewById(R.id.tvItemNickName);
		vh.ivItemUserIcon.setDefaultImage(R.drawable.portrait);
		vh.ivItemUserIcon.setImageUrl(MyApplication.nowUser.getUserIcon());
		vh.tvItemNickName.setText(MyApplication.nowUser.getName());
		vh.tvItemUserInfo.setText(MyApplication.nowUser.getUserInfo());
		vh.tvItemID.setText(MyApplication.nowUser.getId()); 
		vh.tvItemPhone.setText(MyApplication.nowUser.getPhoneNumber()); 
		vh.tvItemQQ.setText(MyApplication.nowUser.getQq()); 
		vh.tvItemEmail.setText(MyApplication.nowUser.getEmailAddr());
	}

	/**
	 * ViewHolder class for the integrated management of the controls in the Activity
	 * 
	 * @author starsfury
	 * 
	 */
	private static class ViewHolder {
		RemoteImageView ivItemUserIcon;// Course icon
		TextView tvItemNickName;// User nickname
		TextView tvItemUserInfo;// User's detail information
		TextView tvItemID;// User ID
		TextView tvItemPhone;// User's phone number
		TextView tvItemQQ;// User's QQ number
		TextView tvItemEmail;// User's e-mail
	}
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		MyApplication.allActivity.remove(this);
		this.finish();
	}

	/**
	 * Launch this Activity from the outside
	 *
	 * @param context context from which Activity should be started
	 */
	public static void launch(Context context) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(context, UserInfoActivity.class);
		context.startActivity(intent);
	}
}
